<template>
  <div>
    <el-select v-model="supplierId" clearable placeholder="请选择品牌" filterable>
      <el-option v-for="supplier in supplierOptions"
                 :key="supplier.id" :label="supplier.name" :value="supplier.id"/>
    </el-select>
  </div>
</template>

<script>
import { getSupplierSimple } from "@/api/base/supplier"
export default {
  name: "SelectSupplier",
  props: {
    value: {
      required: true
    }    
  },
  data() {
    return {
      supplierOptions: [],
      supplierId: this.value,
    }
  },
  watch: {
    value(newVal) {
      this.supplierId = newVal;
    },
    supplierId(newVal, oldVal){
      this.$emit("input", this.supplierId)
    }
  },
  created() {
    this.getSupplierListFun();
  },
  methods: {
    /** 查询品牌列表 */
    getSupplierListFun(){
      getSupplierSimple().then(response => {
        this.supplierOptions = response.data;
      })
    },
  }
};
</script>

